<template>
	<div class="list">
		<page-title :title="title"></page-title>
		<!-- 上拉刷新 -->
		<div class="ls-box" v-for="item in page.list" :key="item.id">
			<router-link :to="{path:'collect',query:{gainId:item.id}}">
				<div class="ls-l"><img :src="item.thumburl?item.thumburl:enterprise.logo_4x3" alt=""></div>
				<div class="ls-r">
					<h4 class="title">{{item.ptitle}}</h4>
					<span class="time">{{item.release_time}}</span>
				</div>
			</router-link>
		</div>
		<infinite-loading @infinite="infiniteHandler">
			<span slot="no-more">
				没有更多了...
			</span>
		</infinite-loading>
	</div>
</template>

<script>
//vux
import { Swiper, SwiperItem, Scroller, Loading, Divider } from 'vux'
//征集
import { findGianPageListByParams } from '@/api/community'
import { getEnterpriseInfo } from "@/api/enterprise";

import InfiniteLoading from 'vue-infinite-loading';
export default {
	data() {
		return {
			//企业id
			eid: this.$route.query.eid,
			//微信菜单配置传过来的参数
			params: this.$route.query.params,
			title: this.$route.query.title,
			pullupConfig: {
				content: '',
				downContent: '',
				upContent: '',
				loadingContent: '加载中...'
			},
			page: {
				totalRow: null,
				pageNumber: 1,
				pageSize: 10,
				lastPage: false,
				list: [],
			},
			//上拉刷新配置
			onFetching: false,
			//企业信息
			enterprise: {},

		}
	},
	methods: {
		//上拉刷新
		async infiniteHandler($state) {
			if (!this.onFetching) {
				this.onFetching = true
				await findGianPageListByParams(this.page.pageNumber, this.page.pageSize, this.eid,this.params).then(res => {
					this.page.list = this.page.list.concat(res.page.list)
					this.onFetching = false
					$state.loaded();
					if (res.page.totalPage <= this.page.pageNumber) {
						$state.complete();
						this.onFetching = true
					}
					this.page.pageNumber++
				}).catch(() => {
					this.onFetching = false
				})
			}
		},
	},
	components: {
		Swiper,
		SwiperItem,
		Loading,
		InfiniteLoading,
	},
	mounted() {
		getEnterpriseInfo().then(resp => {
			this.enterprise = resp.enterprise
			console.log(this.enterprise)
		})
		// 	this.$vux.loading.show({
		// 		text: 'Loading'
		// 	})
		// 	setTimeout(() => {
		// 		findGianPageListByParams(this.page.pageNumber, this.page.pageSize, this.eid, this.wxid, this.openid,this.params).then(res => {
		// 			this.page = res.page
		// 			if (res.page.lastPage) {
		// 				this.page.lastPage = true
		// 				this.$refs.pullUp.disablePullup()
		// 			}
		// 			this.$vux.loading.hide()
		// 		}).catch(_ => {
		// 			console.log(_)
		// 			this.$vux.loading.hide()
		// 		})
		// 	}, 800)
	}
}
</script>

<style scoped>

</style>
